﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Yz.Base;
using Yz.DataAccess.DbAccessses.Interface;
using Yz.Model.Constants;

namespace Yz.Web.Controllers
{
    [Authorize(Roles = UserRoleName.System)]
    public class UpdateController : Controller
    {
        private readonly IYzInitializer _yzInitializer;
        public UpdateController(IYzInitializer yzInitializer)
        {
            _yzInitializer = yzInitializer;
        }
        public IActionResult Index()
        {
            return View();
        }
        /// <summary>
        /// 初始化数据库
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<JsonResult> UpdateDb()
        {
            await _yzInitializer.MigrateDbAsync();
            await _yzInitializer.InitDataAsync();
            return Json(new VmReturn() { Suc = true, Msg = "初始化成功！" });
        }
    }
}
